#include <iostream>
#include <memory>
#include <string>
#include <thread>
#include <grpcpp/grpcpp.h>
#include "../protos/ImageDetection.grpc.pb.h"
#include "../atomic_include/ImageDetection.h"


void imageDetect_func(RequestSignal* request, DetectionResult* reply);


void statusDetect_func(RequestSignal* request, CameraStatus* reply);



class ImageDetection_Service_ServerImpl final : public ::ImageDetection_Package::ImageDetection_Service::Service {
public:
    ImageDetection_Service_ServerImpl() {} 
    

    ::grpc::Status imageDetect(::grpc::ServerContext* context, 
            const ::ImageDetection_Package::RequestSignal* request, 
                ::ImageDetection_Package::DetectionResult* reply) override {

        RequestSignal ImageDetection_Request_t;
        DetectionResult ImageDetection_Reply_t;

        
        
        ImageDetection_Request_t.signal = request->signal();
        
        

        /******************************************************************/
        imageDetect_func(&ImageDetection_Request_t, &ImageDetection_Reply_t);

        /******************************************************************/

        reply->Clear(); // clear reply message
        
        
        reply->set_camera_id(ImageDetection_Reply_t.camera_id);
        
        
        
        reply->set_object_class(ImageDetection_Reply_t.object_class);
        
        
        
        reply->set_confidence(ImageDetection_Reply_t.confidence);
        
        
        
        reply->set_x_min(ImageDetection_Reply_t.x_min);
        
        
        
        reply->set_y_min(ImageDetection_Reply_t.y_min);
        
        
        
        reply->set_x_max(ImageDetection_Reply_t.x_max);
        
        
        
        reply->set_y_max(ImageDetection_Reply_t.y_max);
        
        
        
        reply->set_return_type(ImageDetection_Reply_t.return_type);
        
        
        std::cout << "This is Method = imageDetect,   ServiceName = ImageDetection_Service" << std::endl;
        return grpc::Status::OK;
    }

    

    ::grpc::Status statusDetect(::grpc::ServerContext* context, 
            const ::ImageDetection_Package::RequestSignal* request, 
                ::ImageDetection_Package::CameraStatus* reply) override {

        RequestSignal ImageDetection_Request_t;
        CameraStatus ImageDetection_Reply_t;

        
        
        ImageDetection_Request_t.signal = request->signal();
        
        

        /******************************************************************/
        statusDetect_func(&ImageDetection_Request_t, &ImageDetection_Reply_t);

        /******************************************************************/

        reply->Clear(); // clear reply message
        
        
        reply->set_status_code(ImageDetection_Reply_t.status_code);
        
        
        
        reply->set_description(ImageDetection_Reply_t.description);
        
        
        
        reply->set_return_type(ImageDetection_Reply_t.return_type);
        
        
        std::cout << "This is Method = statusDetect,   ServiceName = ImageDetection_Service" << std::endl;
        return grpc::Status::OK;
    }

    
};